package com.tm.media.login.controller;

import com.tm.media.login.service.IAdMenuService;
import com.tm.media.utils.utils.Result;
import com.tm.media.model.entity.AdMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单权限Controller
 * 
 * @author ruoyi
 * @date 2023-02-12
 */
@RestController
@CrossOrigin
@RequestMapping("system/menu")
public class AdMenuController{
    @Autowired
    private IAdMenuService adMenuService;
    @GetMapping("tree")
    public Result tree(){
        return adMenuService.tree();
    }
    /**
     * 查询菜单权限列表
     */
    @GetMapping("list")
    public Result list(AdMenu adMenu) {
        List<AdMenu> list = adMenuService.selectAdMenuList(adMenu);
        return Result.SUCCESS(list);
    }

    /**
     * 获取菜单权限详细信息
     */
    @GetMapping(value = "/{menuId}")
    public Result getInfo(@PathVariable("menuId") Long menuId)
    {
        return Result.SUCCESS(adMenuService.selectAdMenuByMenuId(menuId));
    }

    /**
     * 新增菜单权限
     */
    @PostMapping
    public Result add(@RequestBody AdMenu adMenu)
    {
        return Result.SUCCESS(adMenuService.insertAdMenu(adMenu));
    }

    /**
     * 修改菜单权限
     */
    @PutMapping
    public Result edit(@RequestBody AdMenu adMenu)
    {
        return Result.SUCCESS(adMenuService.updateAdMenu(adMenu));
    }

    /**
     * 删除菜单权限
     */
    @DeleteMapping("/{menuIds}")
    public Result remove(@PathVariable Long[] menuIds)
    {
        return Result.SUCCESS(adMenuService.deleteAdMenuByMenuIds(menuIds));
    }

}
